package org.peterbjornx.landscape.renderer;

import org.peterbjornx.landscape.Landscape;
import org.peterbjornx.formats.FloorCollection;
import org.peterbjornx.Client;
import org.peterbjornx.model.Player;

import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: PeterbjornX
 * Date: Apr 9, 2009
 * Time: 9:01:13 PM
 * >
 */
public class AWT2DLandscapeRenderer extends AbstractLandscapeRenderer{


    public void renderlandscape(Landscape l, Graphics g, int x, int y, int mx, int my, int gameW, int gameH) {
        int basew = (gameW / 4)/2;
        int baseh = (gameH / 4)/2;
        //for (int gZ = 0; gZ < Landscape.HEIGHT_COUNT;gZ++)
        int gZ = 0;
            for (int x2 = mx - basew; x2 < mx + basew;x2++)
                for (int y2 = my + basew; y2 > my - baseh;y2--){
                    //g.setColor
                    g.setColor(Color.pink);
                    if (x2 < 0 || y2 < 0 || x2 > 255 || y2 > 255)continue;
                    if (l.overlay[gZ][x2][y2] == 0 && l.underlay[gZ][x2][y2] != 0)
                        g.setColor(new Color(FloorCollection.cache[l.underlay[gZ][x2][y2] - 1].colour2));
                    else if (l.overlay[gZ][x2][y2] != 0)
                        g.setColor(new Color(FloorCollection.cache[l.overlay[gZ][x2][y2] - 1].colour2));
                    g.fillRect(x+(x2-(mx-basew ))*4,y+(y2-(my-baseh ))*4,4,4);
                }
        for (int i = 0;i < Client.instance.playerCount;i++){
            Player p = Client.instance.playerArray[Client.instance.playerIndices[i]];
            g.setColor(Color.white);
            g.fillRect(p.x*4,p.y*4,4,4);
        }
    }
}
